<template>
  <starTable
    :ref="ref"
    :data="data"
    v-bind="attrs"
    @loadPage="loadPage"
    @handleEdit="handleEdit"
    @handleDelete="handleDelete"
    @handleDetail="handleDetail"
    @handleClick="handleClick"
    @handleDbClick="handleDbClick"
    @handleCreate="handleCreate"
    @handleDeleteMultiple="handleDeleteMultiple"
    @handleSearch="handleSearch"
    @handleReset="handleReset"
  ></starTable>
</template>

<script>
const ref = "secondTable";
export default {
  name: ref,
  inject: ["anc"],
  data() {
    return {
      ref,
    };
  },
  props: {
    data: {
      default: () => {
        return [];
      },
    },
  },
  watch: {},
  computed: {
    attrs(){
      return {
        config:{
          autoHeight:true,
          search: true,
          addButton: false,
          batchDeleteButton: false,
          downloadIcon: false,
          uploadIcon: false,
          uploadUrl: "/",
          tableSizeIcon: false,
          fullscreenIcon: false,
          refreshIcon: false,
          columnSettingIcon: false,
          checkColumnDisabled: true,
          action: false, // 操作
          additionalAction: false, // 新增自定义
          navigation:true
        },
        loading:false,//是否显示加载中提示
        tableStyle:{},//表格样式
        tableTitle:'',//表格标题
        pageSizeOpts:[10, 30, 50, 100],
        pageNavigation: {
          total: 0,
          pageSize: 10,
          pageNumber: 1,
        },
        queryFormItem:[
          { title: "订单号", key: "orderNo", config: { type: "text" } },
          { title: "订单批次号", key: "batchNo", config: { type: "text" } },
          { title: "重量(KG)", key: "weight", config: { type: "text" } },
          {
            title: "产物规格",
            key: "productId",
            config: { type: "select", options: this.anc.productOptions },
          },
          {
            key: "deliveryDate",
            title: "交货日期",
            minWidth: 100,
            align: "center",
            config: { type: "datetime" },
          },
        ],
        collapseFormItem:[
          {
            key: "orderNo",
            title: "订单号",
            config:{type:'text'}
          },
          {
            key: "batchNo",
            title: "订单批次号",
            config:{type:'text'}
          },
        ],
        btnShowFun:(row,key)=>{return true},
        rowbgc:'',
        columns:[
        {
          key: "orderNo",
          title: "订单号",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "productId",
          title: "产物规格ID",
          minWidth: 200,
          align: "center",
          show: true,
          render: (h, params) => {
            return h(
              "div",
              {},
              this.getOptionValue(this.anc.productOptions, params.row.productId)
            );
          },
        },
        {
          key: "batchNo",
          title: "订单批次号",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "status",
          title: "状态",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "routingId",
          title: "工艺路径",
          minWidth: 100,
          align: "center",
          show: false,
        },
        {
          key: "statusD",
          title: "代加工标识",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "orderFrom",
          title: "订单标识",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "weight",
          title: "重量(T)",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "maxFSSS",
          title: "最大FSSS",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "minFSSS",
          title: "最小FSSS",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "maxCT",
          title: "最大CT",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "minCT",
          title: "最小CT",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "FSSS",
          title: "平均FSSS",
          minWidth: 100,
          align: "center",
          show: true,
        },

        {
          key: "deliveryDate",
          title: "交货日期",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "supplyStandard",
          title: "供货标准",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "packingRequirement",
          title: "包装要求",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "customerInformation",
          title: "客户信息",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "remark",
          title: "备注",
          minWidth: 100,
          align: "center",
          show: false,
        },
        ],
        additionalAction:{
          key: "additionalAction",
          title: "操作",
          slot: "additionalAction",
          width: 200,
          fixed: "right",
          align: "center",
          minWidth: 100,
          show: true,
          show: true,
          buttons: [
            {
              title: "统计成本",
              event: (row, index) => console.log(row),
            },
          ],
        }
      }
    },
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);
      this.loadPage(this.attrs.pageNavigation, {});
    });
  },
  methods: {
    loadPage(pageNavigation, filter, orderBy = "") {
      //   //删除查询项中属性值为空的查询条件
      this.anc.loadPage(pageNavigation, filter, orderBy);
    },
    handleEdit(row, index) {
      console.log(row, index);
      this.anc.handleEdit(row, index);
    },
    handleDelete(row, index) {
      this.anc.handleDelete(row, index);
    },
    handleDetail(row, index) {
      this.anc.handleDetail(row);
    },
    handleClick(row, index) {},
    handleDbClick(row, index) {},
    handleDeleteMultiple(selection) {
      this.anc.handleDeleteMultiple(selection);
    },
    handleSearch(filter) {
      this.attrs.pageNavigation.pageNumber = 1;
      this.loadPage(this.attrs.pageNavigation, filter);
    },
    handleReset() {
      this.attrs.pageNavigation.pageNumber = 1;
      this.loadPage(this.attrs.pageNavigation, {});
    },
    handleCreate() {
      this.anc.handleCreate();
    },
    getOptionValue(options, value, key = "label") {
      let dataValue = "";
      let index = options.findIndex((d) => d.value === value);
      if (index !== -1) {
        dataValue = options[index][key];
      }
      return dataValue;
    },
  },
};
</script>
<style scoped></style>
